package com.lagou.edu.controller;

import com.lagou.edu.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/email")
public class EmailController {
    @Autowired
    private EmailService emailService;

    /**
     * 发送验证码到邮箱，true成功，false失败
     */
    @RequestMapping("/{email}/{code}")
    public Boolean sendEmail(
            @PathVariable("email") String email,
            @PathVariable("code") String code) {
        boolean flag = true;
        try {
            emailService.sendEmail(email, code);
        } catch (Exception e) {
            flag = false;
            e.printStackTrace();
        }

        return flag;
    }

}
